<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Using XML</title>
	<link rel="stylesheet" type="text/css" href="../media/style.css">
	<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
	<script src="media/a.js"></script>
</head>
<body>

<table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
  <tr>
	<td class="header-top-left"><img src="../media/logo.png" border="0" alt="phpDocumentor " /></td>
    <td class="header-top-right">QueryPath<br /><div class="header-top-right-subpackage"></div></td>
  </tr>
  <tr><td colspan="2" class="header-line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
  <tr>
    <td colspan="2" class="header-menu">
      
                        
                                                  		[ <a href="../classtrees_QueryPath.html" class="menu">class tree: QueryPath</a> ]
		[ <a href="../elementindex_QueryPath.html" class="menu">index: QueryPath</a> ]
            [ <a href="../elementindex.html" class="menu">all elements</a> ]
    </td>
  </tr>
  <tr><td colspan="2" class="header-line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="195" class="menu">
		<div class="package-title">QueryPath</div>
  <div class="package">
	<div id="todolist">
			<p><a href="../todolist.html">Todo List</a></p>
	</div>
	</div>
      <b>Packages:</b><br />
  <div class="package">
              <a href="../li_QueryPath.html">QueryPath</a><br />
              <a href="../li_Examples.html">Examples</a><br />
              <a href="../li_Tests.html">Tests</a><br />
      	</div>
      <br />
                        <br />
                      </td>
    <td>
      <table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">

<h1 align="center">Using XML</h1>
<div class="src-code"><span class="php">
<ol><li><div class="src-line"><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line"><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;Using&nbsp;QueryPath.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;This&nbsp;file&nbsp;contains&nbsp;an&nbsp;example&nbsp;of&nbsp;how&nbsp;QueryPath&nbsp;can&nbsp;be&nbsp;used</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;to&nbsp;generate&nbsp;XML.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;QueryPath's&nbsp;ability&nbsp;to&nbsp;handle&nbsp;arbitrary&nbsp;XML&nbsp;comes&nbsp;in&nbsp;handy.&nbsp;Fragments&nbsp;of&nbsp;HTML</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;can&nbsp;be&nbsp;composed&nbsp;as&nbsp;external&nbsp;XML&nbsp;documents,&nbsp;and&nbsp;then&nbsp;inserted&nbsp;selectively&nbsp;into</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;an&nbsp;HTML&nbsp;document&nbsp;as&nbsp;needed.&nbsp;Just&nbsp;remember:&nbsp;Ever&nbsp;XML&nbsp;document&nbsp;--&nbsp;even&nbsp;just&nbsp;a</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;string&nbsp;--&nbsp;needs&nbsp;to&nbsp;begin&nbsp;with&nbsp;the&nbsp;XML&nbsp;declaration:</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;&lt;code&gt;</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;&lt;?&nbsp;xml&nbsp;version=&quot;1.0&quot;?&gt;</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;&lt;/code&gt;</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;(A&nbsp;space&nbsp;was&nbsp;inserted&nbsp;above&nbsp;to&nbsp;prevent&nbsp;the&nbsp;documentation&nbsp;renderer&nbsp;from</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;misinterpreting&nbsp;it.)</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@package</span><span class="src-doc">&nbsp;Examples</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@author</span><span class="src-doc">&nbsp;M&nbsp;Butcher&nbsp;&lt;matt@aleph-null.tv&gt;</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@license</span><span class="src-doc">&nbsp;LGPL&nbsp;The&nbsp;GNU&nbsp;Lesser&nbsp;GPL&nbsp;(LGPL)&nbsp;or&nbsp;an&nbsp;MIT-like&nbsp;license.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-inc">require_once&nbsp;</span><span class="src-str">'../src/QueryPath/QueryPath.php'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;Create&nbsp;a&nbsp;new&nbsp;XML&nbsp;document&nbsp;wrapped&nbsp;in&nbsp;a&nbsp;QueryPath.</span></div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;By&nbsp;default,&nbsp;it&nbsp;will&nbsp;point&nbsp;to&nbsp;the&nbsp;root&nbsp;element,</span></div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;&lt;author/&gt;</span></div></li>
<li><div class="src-line"><span class="src-var">$record&nbsp;</span>=&nbsp;<a href="../QueryPath/_src---QueryPath---QueryPath.php.html#functionqp">qp</a><span class="src-sym">(</span><span class="src-str">'&lt;?xml&nbsp;version=&quot;1.0&quot;?&gt;&lt;author&gt;&lt;/author&gt;'</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;Add&nbsp;a&nbsp;new&nbsp;last&nbsp;name&nbsp;inside&nbsp;of&nbsp;author.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><span class="src-id">append</span><span class="src-sym">(</span><span class="src-str">'&lt;lastName&gt;Dostoyevsky&lt;/lastName&gt;'</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;Select&nbsp;all&nbsp;of&nbsp;the&nbsp;children&nbsp;of&nbsp;&lt;author/&gt;.&nbsp;In&nbsp;this&nbsp;case,</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;that&nbsp;is&nbsp;&lt;lastName/&gt;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><span class="src-id">children</span><span class="src-sym">(</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;Oh,&nbsp;wait...&nbsp;we&nbsp;wanted&nbsp;last&nbsp;name&nbsp;to&nbsp;be&nbsp;inside&nbsp;of&nbsp;a&nbsp;&lt;name/&gt;&nbsp;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;element.&nbsp;Use&nbsp;wrap&nbsp;to&nbsp;wrap&nbsp;the&nbsp;current&nbsp;element&nbsp;in&nbsp;something:</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><span class="src-id">wrap</span><span class="src-sym">(</span><span class="src-str">'&lt;name/&gt;'</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;And&nbsp;before&nbsp;last&nbsp;name,&nbsp;we&nbsp;want&nbsp;to&nbsp;add&nbsp;first&nbsp;name.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><span class="src-id">before</span><span class="src-sym">(</span><span class="src-str">'&lt;firstName/&gt;'</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;Select&nbsp;first&nbsp;name</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><a href="http://www.php.net/prev">prev</a><span class="src-sym">(</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;Set&nbsp;the&nbsp;text&nbsp;of&nbsp;first&nbsp;name</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><span class="src-id">text</span><span class="src-sym">(</span><span class="src-str">'Fyodor'</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;And&nbsp;then&nbsp;after&nbsp;first&nbsp;name,&nbsp;add&nbsp;the&nbsp;patronymic</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><span class="src-id">after</span><span class="src-sym">(</span><span class="src-str">'&lt;patronymic&gt;Fyodorovich&lt;/patronymic&gt;'</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;Now&nbsp;go&nbsp;back&nbsp;to&nbsp;the&nbsp;root&nbsp;element,&nbsp;the&nbsp;top&nbsp;of&nbsp;the&nbsp;document.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><span class="src-id">top</span><span class="src-sym">(</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;Add&nbsp;another&nbsp;tag&nbsp;--&nbsp;origin.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><span class="src-id">append</span><span class="src-sym">(</span><span class="src-str">'&lt;origin&gt;Russia&lt;/origin&gt;'</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;turn&nbsp;the&nbsp;QueryPath&nbsp;contents&nbsp;back&nbsp;into&nbsp;a&nbsp;string.&nbsp;Since&nbsp;we&nbsp;are&nbsp;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;at&nbsp;the&nbsp;top&nbsp;of&nbsp;the&nbsp;document,&nbsp;the&nbsp;whole&nbsp;document&nbsp;will&nbsp;be&nbsp;converted</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-comm">//&nbsp;to&nbsp;a&nbsp;string.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-sym">-&gt;</span><span class="src-id">xml</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-comm">//&nbsp;Print&nbsp;our&nbsp;results.</span></div></li>
<li><div class="src-line">print&nbsp;<span class="src-var">$record</span><span class="src-sym">;</span></div></li>
</ol>
</span></div>
        <div class="credit">
		    <hr class="separator" />
		    Documentation generated on Thu, 19 Mar 2009 18:01:18 -0500 by <a href="http://www.phpdoc.org">phpDocumentor 1.4.2</a>
	      </div>
      </td></tr></table>
    </td>
  </tr>
</table>

</body>
</html>